library(dplyr)
library(lubridate)
library(MASS)
library(DHARMa)
library(haven)
library(car)
library(hnp)

tun_ec <- read_dta("/Users/christopherbarrie/Dropbox/Egypt Event Data/Egypt Mobilization Book/temporal_protest/production/replication/data/tun_prot_expanded.dta")

#reformat date to r readable
tun_ec$date <- as.Date(tun_ec$date)

tun_ec$day <- weekdays(as.Date(tun_ec$date))
mod1 <- glm.nb(ppart~ day, data=tun_ec)
summary(mod1)
plot(mod1, which = 1)

fit1_p <- glm.nb(ppart ~ day, data=tun_ec)
anova(fit1_p, test = "Chisq")
hnp(fit1_p, xlab = "Half-normal scores", ylab = "Deviance residuals", pch = 4)
influenceIndexPlot(mod1, vars = "Studentized", main = "Influence plot", grid = F)

egy_ec <- read_dta("/Users/christopherbarrie/Dropbox/Egypt Event Data/Egypt Mobilization Book/temporal_protest/production/replication/data/egy_prot_expanded.dta")

#reformat date to r readable
egy_ec$date <- as.Date(egy_ec$date)

egy_ec$day <- weekdays(as.Date(egy_ec$date))
mod1 <- glm.nb(ppart~ day, data=egy_ec)
summary(mod1)
plot(mod1, which = 1)

fit1_p <- glm.nb(ppart ~ day, data=egy_ec)
anova(fit1_p, test = "Chisq")
hnp(fit1_p, xlab = "Half-normal scores", ylab = "Deviance residuals", pch = 4)
influenceIndexPlot(mod1, vars = "Studentized", main = "Influence plot", grid = F)
